package indi.caibo.service_edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import indi.caibo.service_edu.entity.EduCourseCollect;
import indi.caibo.service_edu.mapper.EduCourseCollectMapper;
import indi.caibo.service_edu.service.EduCourseCollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程收藏 服务实现类
 * </p>
 *
 * @author Bo Cai
 * @since 2021-12-21
 */
@Service
public class EduCourseCollectServiceImpl extends ServiceImpl<EduCourseCollectMapper, EduCourseCollect> implements EduCourseCollectService {

    @Override
    public void collect(String memberId, String courseId) {
        EduCourseCollect courseCollect = new EduCourseCollect();
        courseCollect.setMemberId(memberId);
        courseCollect.setCourseId(courseId);
        baseMapper.insert(courseCollect);
    }

    @Override
    public Boolean isCollected(String memberId, String courseId) {
        List<EduCourseCollect> courseCollectList = baseMapper.selectList(new QueryWrapper<EduCourseCollect>().eq("course_id", courseId).eq("member_id", memberId));
        return courseCollectList != null && courseCollectList.size() > 0;
    }

    @Override
    public void cancelCollect(String memberId, String courseId) {
        baseMapper.delete(new QueryWrapper<EduCourseCollect>().eq("course_id", courseId).eq("member_id", memberId));
    }

    @Override
    public List<String> getCourseIdsByMemberId(String memberId) {
        return baseMapper.selectCourseIdsByMemberId(memberId);
    }
}
